package com.xjc.common;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;


/**
 * <p>
 * http请求工具类
 * </p>
 *
 * @author xiaojincai
 * @since 2025-06-20
 */
@Slf4j
@SuppressWarnings("all")
public class HttpRequestUtil {

    /**
     * 发送请求
     *
     * @param request        请求对象
     * @param responseType   响应对象类型
     * @param apiDescription 接口描述
     */
    public static <T> T sendRequest(HttpRequest request, TypeReference<T> responseType, String apiDescription) {
        long t1 = System.currentTimeMillis();
        final String body = request.execute().body();
        log.info("{}接口响应时间:{}ms,响应结果:{}", apiDescription, System.currentTimeMillis() - t1, body);
        return JSONUtil.toBean(body, responseType, false);
    }

}
